* Reset settings and initialize log file
launch, path("share/life_cycle")

*-------------------------------------------------------------------------------
* Price and Wasserman (2024), "The Summer Drop in Female Employment"
*
* Description: Show the summer drop as a function of own age.
*-------------------------------------------------------------------------------


* Prepare data and run models
*-------------------------------------------------------------------------------

if "$estimate" != "0" {
	* Load data on adult individuals
	gzuse "$basepath/data/derived/cps_bms_sample_allages.dta.gz", clear

	* Retain a broader-than-usual age range
	keep if inrange(age, 20, 65)

	* Aggregate to the age x year x month level
	gcollapse (mean) emp (rawsum) wtfinl (first) year month tmspline* weeks [pw = wtfinl], by(female age tm)

	* Store the data
	tempfile core
	save `core'

	* Compute May-July gaps in female/male employment by age, net of year effects
	foreach f of numlist 0 1 {
		forvalues a = 20/65 {
			use if female == `f' & age == `a' using `core', clear
			quietly tsset tm
			quietly ivreg2 emp ib5.month tmspline* weeks [pw = wtfinl], bw($bandwidth) robust small
			process_estimates, path("life_cycle") model("f`f'_a`a'") mayjuly
		}
	}
}


* Prepare estimates
*-------------------------------------------------------------------------------

* Load estimates into memory
load_estimates, path("life_cycle")

* Construct a dataset of estimates
tempfile coefs
postfile coefs byte female age float beta stde using `coefs', replace

foreach f of numlist 0 1 {
	forvalues a = 20/65 {
		quietly estimates restore f`f'_a`a'
		post coefs (`f') (`a') (_b[mayjuly]) (_se[mayjuly])
	}
}

postclose coefs
use `coefs', clear

* Rescale estimates
replace beta = 100 * beta
replace stde = 100 * stde

* Construct confidence intervals
gen beta_low = beta - 1.96 * stde
gen beta_upp = beta + 1.96 * stde

* Prepare shading
gen lower = -4.5
gen upper = +8.5
gen age_adj = age - 0.5

* Offset coefficients for visual clarity
gen age_low = age - 0.05
gen age_upp = age + 0.05


* Plot estimates
*-------------------------------------------------------------------------------

* Plot the employment patterns
#delimit ;
twoway
	(rarea upper lower age_adj if inrange(age, 25, 50), color($ltgs) plotregion(margin(t=0 b=0)))
	(scatteri 0 20 0 65, recast(line) color(black))
	(rcap beta_low beta_upp age_low if female == 1, color($col1) msize(zero))
	(connected beta age_low if female == 1, color($col1) msymbol($sym1))
	(rcap beta_low beta_upp age_upp if female == 0, color($col2) msize(zero))
	(connected beta age_upp if female == 0, color($col2) msymbol($sym2)),
	title("")
	xtitle("Age")
	xscale(range(19.5 65.5))
	xlabel(20(5)65)
	xtick(20(1)65)
	ytitle("Change from May to July (p.p.)")
	yscale(range(-4.5 8.5))
	ylabel(-4(2)8, format(%5.1fc))
	yline(0)
	graphregion(margin(t=0 b=0 l=2 r=2))
	plotregion(margin(zero))
	legend(rows(1) order(4 6) label(4 "Women") label(6 "Men"));
#delimit cr

nicepdf "$basepath/output/life_cycle.pdf", indirect replace

* Close the log file
unlaunch
